package com.gxa.service.employee.impl;

import com.gxa.common.R.ResponseData;
import com.gxa.mapper.employee.AddEmployeeMapper;
import com.gxa.pojo.Employee;
import com.gxa.service.employee.AddEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class AddEmployeeServiceImpl implements AddEmployeeService {
    @Autowired(required = false)
    private AddEmployeeMapper addEmployeeMapper;
    /**
     * 返回录入员工的新编号
     * @return
     */
    @Override
    public ResponseData nextEmployeeId() {
        ResponseData responseData = new ResponseData();
        HashMap<String, Integer> map = new HashMap<>();
        Integer maxid = addEmployeeMapper.selectNextEmployeeId();
        int newId = maxid + 1;
        map.put("id",newId);
        responseData.setCode(200);
        responseData.setMsg("录入员工信息id");
        responseData.setData(map);
        return responseData;
    }

    /**
     * 录入员工信息
     *
     * @param employee
     * @return
     */
    @Override
    public ResponseData addEmployee(Employee employee) {
        ResponseData responseData = new ResponseData();
        System.out.println("状态states=  "+employee.getStates());
        if (employee.getStates() == 0){
            employee.setStates(1);
        }
        addEmployeeMapper.insertEmployeeInfo(employee);
        responseData.setCode(200);
        responseData.setMsg("录入员工信息成功");
        return responseData;
    }
}
